﻿using System;
using System.Collections.Generic;
using EnvDTE;
using EnvDTE80;


namespace VsTortoiseSVN.Commands
{
    public class SolutionExplorerSelectedItemsLog : SolutionExplorerSelectedItemsBase
    {
        public SolutionExplorerSelectedItemsLog(DTE2 application, string name, string caption, string tooltip, int bitmapId)
            : base(application, name, caption, tooltip, bitmapId)
        {
        }

        protected override vsCommandStatus QueryContextSensitiveStatus()
        {
            return QueryStatusImpl();
        }

        protected override vsCommandStatus QueryContextInsensitiveStatus()
        {
            return QueryStatusImpl();
        }

        public override bool Exec()
        {
            string fullName = SvnHelper.GetShowLogPath(GetFullNames());
            TortoiseProc.Instance.ShowLog(fullName);
            return true;
        }

        private vsCommandStatus QueryStatusImpl()
        {
            if(Application.SelectedItems.Count == 1)
            {
                string fullName = SvnHelper.GetShowLogPath(GetFullNames());
                if(!string.IsNullOrEmpty(fullName))
                {
                    if (SvnHelper.IsVersionControlled(fullName))
                        return vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                }
            }

            return vsCommandStatus.vsCommandStatusUnsupported;
        }
    }
}
